package com.ruoyi.model.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.model.domain.Model;
import com.ruoyi.model.service.IModelService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;


import com.ruoyi.common.core.page.TableDataInfo;

/**
 * modelController
 *
 * @author ruoyi
 * @date 2025-01-09
 */
@RestController
@RequestMapping("/model")
public class ModelController extends BaseController
{
    @Autowired
    private IModelService modelService;

    /**
     * 查询model列表
     */

    @GetMapping("/list")
    public TableDataInfo list(Model model)
    {
        startPage();
        List<Model> list = modelService.selectModelList(model);
        return getDataTable(list);
    }

    /**
     * 导出model列表
     */

    @PostMapping("/export")
    public void export(HttpServletResponse response, Model model)
    {
        List<Model> list = modelService.selectModelList(model);
        ExcelUtil<Model> util = new ExcelUtil<Model>(Model.class);
        util.exportExcel(response, list, "model数据");
    }

    /**
     * 获取model详细信息
     */

    @GetMapping(value = "/selectOne/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(modelService.selectModelById(id));
    }

    /**
     * 新增model
     */

    @PostMapping("/add")
    public AjaxResult add(@RequestBody Model model)
    {
        return toAjax(modelService.insertModel(model));
    }

    /**
     * 修改model
     */

    @PutMapping("/update")
    public AjaxResult edit(@RequestBody Model model)
    {
        return toAjax(modelService.updateModel(model));
    }

    /**
     * 删除model
     */

	@DeleteMapping("/del/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(modelService.deleteModelByIds(ids));
    }
}
